//async_await结合读取3个文件

const fs = require("fs")

function readFile(path) {
    return new Promise((resolve, reject)=>{
        fs.readFile(path, (err,data)=>{
            if(err){
                //失败
                reject(err)
            }else{
                //成功
                resolve(data)
            }
        })
    })
}

let path1 = "./resources/为学.md"
let path2 = "./resources/为学2.md"
let path3 = "./resources/为学3.md"

//用async await代替then、catch方法
async function main() {
    let res1 = await readFile(path1) //readFile方法未完成时，await会阻塞直到完成
    let res2 = await readFile(path2)
    let res3 = await readFile(path3)
    console.log(res1 + "\n" + res2 + "\n" + res3)
}

main()